"use strict"
const mosca = require('mosca')

let mqttServer = new mosca.Server({
  http: {
    port: 3000,
    bundle: true,
    static: './'
  },
  persistence: {
    factory: mosca.persistence.Memory
  }
})

mqttServer.on('clientConnected', (client) => {
  console.log(client.id)
})

mqttServer.on('published', (packet, client) => {
  let topic = packet.topic
  console.log(`${topic}:${packet.payload.toString()}`)
})

mqttServer.on('ready', () => {
  console.log('mqtt is running...')
})